package com.mojito.learn.algorithm;

import com.mojito.learn.algorithm.datastructure.ListNode;

/**
 * @author liufq
 * @since 2022/4/10 下午4:27
 */
public class Test {

    public static void main(String[] args) {
//        System.out.println(new Test().test(ListNode.build("[1,2,2]")));
        System.out.println(new Test().test(ListNode.build("[1,2,3,4,4,5]")));
        System.out.println(new Test().test(ListNode.build("[1,1,1,1]")));
    }

    public ListNode test(ListNode node) {
        ListNode prev = node;
        ListNode next = node;
        while (node != null && node.next != null) {
            if (node.next.val != node.val) {
                node = node.next;
                next = next.next;
            } else {
                node = node.next.next;
                prev.next = node;
            }
        }
        return prev;
    }
}
